namespace Game {
	public sealed class ShipReactor : IReactor, IEnergySource {
		public float GenerationRate { get; set; }  = 100; //Energy units per sec
		public float BatteryCapacity { get; set; } = 3000;

		public float EnergyLevel { get; set; }

		ShipCore _core;
		bool _dryRun;

		public ShipReactor(ShipCore shipCore) {
			_core = shipCore;
			EnergyLevel = BatteryCapacity;
			_dryRun = !GameManager.Instance.IsServer;
		}

		public bool HasEnergy(float requiredAmount) {
			if ( _dryRun ) {
				return true;
			}
			return EnergyLevel > requiredAmount;
		}

		public bool UseEnergy(float amount ) {
			if ( _dryRun ) {
				return true;
			}
			EnergyLevel -= amount;
			if ( EnergyLevel < 0 ) {
				EnergyLevel = 0;
				return false;
			}
			return true;
		}

		public void Update(float deltaTime) {
			EnergyLevel += deltaTime * GenerationRate;
			if ( EnergyLevel > BatteryCapacity ) {
				EnergyLevel = BatteryCapacity;
			}
		}
	}
}

